package com.htzos.admin.ac.controller;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.htzos.admin.ac.bean.AcNoticeBase;
import com.htzos.admin.ac.service.AcNoticeBaseService;
import com.htzos.admin.system.bean.SystemUserBase;
import com.htzos.base.parent.ctrl.BaseController;
import com.htzos.common.tool.ExtQueryBean;
import com.htzos.common.util.CommonUtil;
import com.htzos.common.util.HtmlUtil;

@Controller
@RequestMapping("/acNoticeBase")
public class AcNoticeBaseController extends BaseController{

    @Resource
    AcNoticeBaseService acNoticeBaseService;

    @RequestMapping("/list")
    public ModelAndView list(HttpServletRequest request,AcNoticeBase condition, ExtQueryBean extQuery) {
        if(extQuery.getPageNum() == null) {
            extQuery.setSize(10);
            extQuery.setPageNum(1);
        }

        extQuery.setTotal(acNoticeBaseService.acNoticeBaseTotal(condition, extQuery));
        List<AcNoticeBase> list= acNoticeBaseService.acNoticeBaseList(condition, extQuery);
        request.setAttribute("list", list);
        request.setAttribute("condition", condition);
        request.setAttribute("extQuery", extQuery);
        request.getSession(true).setAttribute("conditionStr", condition);
        request.getSession(true).setAttribute("extQueryStr", extQuery);
        return new ModelAndView("admin/ac/acNoticeBaseList");
    }

    @RequestMapping("/update")
    public ModelAndView update(HttpServletRequest request, AcNoticeBase acNoticeBase) {
    	acNoticeBase.setTitle(HtmlUtil.delHTMLTag(acNoticeBase.getTitle()));
    	acNoticeBase.setContent(HtmlUtil.delHTMLTag(acNoticeBase.getContent()));
        acNoticeBaseService.acNoticeBaseUpdate(acNoticeBase);
        return new ModelAndView(new RedirectView("list"), getSessionQueryString(request));
    }

    @RequestMapping("/updatePage")
    public String updatePage(HttpServletRequest request, String id) {
        AcNoticeBase acNoticeBase = acNoticeBaseService.acNoticeBaseGet(id);
        request.setAttribute("acNoticeBase", acNoticeBase);
        return "admin/ac/acNoticeBaseUpdate";
    }

    @RequestMapping("/insert")
    public ModelAndView insert(HttpServletRequest request, AcNoticeBase acNoticeBase) {
    	
    	acNoticeBase.setCreateTime(new Date());
    	
    	
    	SystemUserBase user = (SystemUserBase) request.getSession().getAttribute(CommonUtil.CURRENTUSER);
    	
    	acNoticeBase.setCreatUser(user.getUserName());
    	acNoticeBase.setTitle(HtmlUtil.delHTMLTag(acNoticeBase.getTitle()));
    	acNoticeBase.setContent(HtmlUtil.delHTMLTag(acNoticeBase.getContent()));
        acNoticeBaseService.acNoticeBaseInsert(acNoticeBase);
        return new ModelAndView(new RedirectView("list"), getSessionQueryString(request));
    }
    @RequestMapping("/addPage")
    public String addPage() {
        return "admin/ac/acNoticeBaseAdd";
    }

    @RequestMapping("/delete")
    public ModelAndView delete(HttpServletRequest request, AcNoticeBase acNoticeBase) {
        acNoticeBaseService.acNoticeBaseDelete(acNoticeBase);
         return new ModelAndView(new RedirectView("list"), getSessionQueryString(request));
    }
}